package com.wuchao.spring.advice;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Service;

import java.util.Arrays;

/**
 * @Author wuchao66
 * @Date 2022/7/4 12:25
 * @Version 1.0
 */
@Service
@Aspect
@Slf4j
public class Advice {
    @Before("execution(* com.wuchao.spring.advice.PointCut.show())")
    public void before(JoinPoint jp) {
        log.info("调用" + jp.getTarget() + "的" + jp.getSignature().getName() + "方法。方法入参:" + Arrays.toString(jp.getArgs()));
    }
    @AfterReturning("execution(* com.wuchao.spring.advice.PointCut.show())")
    public void afterReturning(JoinPoint jp) {
        log.info("调用" + jp.getTarget() + "的" + jp.getSignature().getName() );
    }

    public void afterThrowing(Exception e){
        log.info("报错了");
    }
}
